<?php
/**
 * Created by PhpStorm.
 * User: 64423
 * Date: 2018/10/11
 * Time: 15:25
 */

namespace app\shop\admin;

use app\admin\controller\Admin;
use app\shop\model\OrderModel;
use app\common\builder\ZBuilder;

class Order extends Admin
{
    public function index()
    {
        $map = $this->getMap();
        $list = OrderModel::getList($map);
        $page = $list->render();
        $btn = [
            'title' => '查看',
            'icon' => 'fa fa-fw fa-list-alt',
            'href' => url('detail',['id' =>'__order_id__'])
        ];
        $rows = [
            ['order_sn', '订单号'],
            ['user_name','收货人'],
            ['order_amount','应付金额'],
            ['order_status','订单状态','status','',[0=>'待付款:danger',1=>'待发货:warning',2=>'待收货:info',3=>'已完成:success']],
            ['pay_status','支付状态','status','',[0=>'未支付:danger',1=>'已支付:success']],
            ['shipping_status','发货状态','status','',[0=>'未发货:warning',1=>'已发货:success']],
            ['add_time','下单时间','datetime'],
            ['right_button','操作']
        ];
        return ZBuilder::make('table')
            ->setPageTitle('订单列表')
            ->addTimeFilter('add_time')
            ->setSearch(['order_sn' => '订单号']) // 设置搜索参数
            ->setPrimaryKey('order_id')
            ->hideCheckbox()
            ->addColumns($rows)
            ->addRightButton('detail',$btn)
            ->setPages($page)
            ->setRowList($list)
            ->fetch();
    }

    public function detail($id)
    {

        $info = OrderModel::getOne($id);
        $this->assign('order',$info);
        return $this->fetch();
        return ZBuilder::make('form')
            ->addFormItems([
                ['static','order_id','订单ID',''],
                ['static','order_sn','订单号',''],
                ['static','user_id','用户ID','',''],
                ['static','nickname','微信昵称'],
                ['static','order_amount','应付金额',''],
                ['static','order_status','订单状态'],
                ['static','add_time','下单时间',''],
                ['static','pay_time','支付时间'],
                ['static','pay_name','支付方式'],
                ['static','aa','支付方式'],
                ['static','user_name','收货人'],
                ['static','tel_number','联系方式'],
                ['static','address','地址'],
                ['static','shipping_name','快递名称'],
                ['static','shipping_code','快递单号'],
                ['static','user_message','留言'],
            ])
            ->layout([
                'order_id'=>3,'order_sn'=>3, 'user_id'=>3,'nickname'=>3,'order_amount'=>3,'order_status'=>3,
                'add_time'=>3,'pay_time'=> 3,'user_name'=> 3,'tel_number'=> 3,'address'=> 3,'shipping_name'=> 3,
                'shipping_code'=> 3,'user_message'=> 3
            ])
            ->addHidden('id')
            ->setUrl(url('editFirst'))
            ->hideBtn('submit,back')
            ->addBtn('<button class="btn btn-default" type="button" onclick="javascript:history.back(-1);return false;">返回</button>')
            ->setFormData($info)
            ->fetch();

    }


}